package com.example.controller;

import com.example.annotation.AsyncMessageHandler;
import com.example.entity.Canteen;
import com.example.service.CanteenService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/canteen")
@Tag(name = "食堂管理")
public class CanteenController {
    @Autowired
    private CanteenService canteenService;

    @GetMapping("/uuid/{uuid}")
    public Canteen getByUuid(@PathVariable String uuid) {
        return canteenService.getByUuid(uuid);
    }

    @PutMapping
    @Operation(summary = "修改食堂信息")
    @PreAuthorize("hasRole('ADMIN') or hasRole('SUPER_ADMIN')")
    @AsyncMessageHandler(queue = "canteen.update.queue")
    public boolean updateCanteen(@RequestBody Canteen canteen) {
        return canteenService.updateCanteen(canteen);
    }

    @PutMapping("/{id}/status")
    @Operation(summary = "更新食堂状态")
    @PreAuthorize("hasRole('ADMIN') or hasRole('SUPER_ADMIN')")
    @AsyncMessageHandler(queue = "canteen.status.queue")
    public boolean updateStatus(@PathVariable Long id, @RequestParam Integer status) {
        return canteenService.updateStatus(id, status);
    }
} 